package com.wokeMy.view.adpter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wokeMy.view.model.Ticket;
import com.wokeMy.view.util.Util;
import com.zhongcai.online.R;

import java.util.ArrayList;


/**
 * Created by Administrator on 2017-11-22.
 */

public class RecordAdapter extends BaseAdapter {
    private LayoutInflater inflater;
    ArrayList<Ticket> tickets;
    public RecordAdapter(Context context,ArrayList<Ticket> tickets) {
        this.inflater = LayoutInflater.from(context);
        this.tickets=tickets;
    }

    @Override
    public int getCount() {
        return tickets.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHold viewHold;
        if (convertView==null){
            viewHold=new ViewHold();
            convertView=inflater.inflate(R.layout.item_record_lv,null);
            viewHold.iv=(ImageView) convertView.findViewById(R.id.lrc_image);
            viewHold.tvTitle=(TextView) convertView.findViewById(R.id.lrc_title);
            viewHold.tvState=(TextView) convertView.findViewById(R.id.lrc_state);
            viewHold.tvTime=(TextView) convertView.findViewById(R.id.lrc_time);
            viewHold.tvMoney=(TextView) convertView.findViewById(R.id.lrc_momey);
            convertView.setTag(viewHold);
        }else {
            viewHold=(ViewHold)convertView.getTag();
        }
        Ticket ticket = tickets.get(position);
        viewHold.tvTitle.setText(ticket.getTitle());
        int res;
        switch (ticket.getLotteryid()) {
            case "118":
                res=R.mipmap.double_ball;
                break;
            case "106":
                res=R.mipmap.happy_ball;
                break;
            case "123":
                res=R.mipmap.night_ball;
                break;
            default:
                res=R.mipmap.double_ball;
                break;
        }
        viewHold.iv.setBackgroundResource(res);
        String  status;
        if (ticket.getErrormsg()==null){
            status="投注失败";
            viewHold.tvState.setTextColor(Color.BLACK);
        }else {
            //出票状态 0不可出票 1可出票状态 2出票成功 3出票失败(允许再出票）4出票中 5出票中（体彩中心）6出票失败（不允许出票） 99 为空
            if (ticket.getTicketstatus().equals("99")||ticket.getTicketstatus().equals("4")||ticket.getTicketstatus().equals("5")) {
                status="出票中";
                viewHold.tvState.setTextColor(Color.BLACK);
            }else {
                if (ticket.getTicketstatus().equals("2")||ticket.getTicketstatus().equals("1")){
                    //2出票成功
                    switch (ticket.getZjstatus()) {
                        case "":
                            status="等待开奖";
                            viewHold.tvState.setTextColor(Color.BLACK);
                            break;
                        case "0":
                            viewHold.tvState.setTextColor(Color.BLACK);
                            status="等待开奖";
                            break;
                        case "1":
                            viewHold.tvState.setTextColor(Color.BLACK);
                            status="未中奖";
                            break;
                        case "2":
                            status="中奖"+Util.twoString(Integer.valueOf(ticket.getPrebonusvalue())/100+"")+"元";
                            viewHold.tvState.setTextColor(Color.RED);
                            break;
                        case "5":
                            status="等待开奖";
                            viewHold.tvState.setTextColor(Color.BLACK);
                            break;
                        default:
                            status="等待开奖";
                            viewHold.tvState.setTextColor(Color.BLACK);
                            break;
                    }
                }else {
                    status="投注失败";
                    viewHold.tvState.setTextColor(Color.BLACK);
                }
            }

        }
        viewHold.tvState.setText(status);
        viewHold.tvTime.setText(Util.getStrTi(ticket.getCreatetime()));
        viewHold.tvMoney.setText("投注"+ticket.getLotteryvalue()+"元");
        return convertView;
    }
    class ViewHold {
        ImageView iv;
        TextView tvTitle;
        TextView tvState;
        TextView tvTime;
        TextView tvMoney;
    }
}
